/**
 * Copyright (C), 1968-2019, 美的集团股份有限公司
 * FileName: ApiResponseEx
 * Author:   fanyl5
 * Date:     2019/4/14 15:49
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.ruiysoft.crm.model;

import com.ruiysoft.crm.constants.CrmConstants;
import lombok.Data;

/**
 * @Description:
 * @author: fanyl5
 * @date: 2019/4/14 15:49
 * @version: 1.0.0
 */
@Data
public class ApiResponseEx<T> {

    int code;
    Object data;
    String status;

    public ApiResponseEx() {
        this.code = CrmConstants.OK;
        this.status = "success";
    }

    public ApiResponseEx(T data) {
        this();
        this.data = data;
    }

    public static <T> ApiResponseEx<T> with(T t, int code) {
        ApiResponseEx apiResponseEx = new ApiResponseEx();
        apiResponseEx.setStatus("success");
        apiResponseEx.setCode(code);
        apiResponseEx.setData(t);

        return apiResponseEx;
    }

    public static <T> ApiResponseEx<T> error(String message, int code) {
        ApiResponseEx apiResponseEx = new ApiResponseEx();
        apiResponseEx.setCode(code);
        apiResponseEx.setData(message);
        apiResponseEx.setStatus("error");
        return apiResponseEx;
    }
}
